<!--
<link rel="shortcut icon" href="<?php echo base_url() ?>static/images/logoTelkomsel-favico.png" />
<link href="<?php echo base_url() ?>static/css/bootstrap.css" rel="stylesheet"/>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>static/css/main.css" />
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>static/select2/select2.css" />
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>static/select2/select2-bootstrap.css" />
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>static/css/jquery.datetimepicker.css"/>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>static/js/Metro-UI-CSS/min/iconFont.min.css"/>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>static/css/print.css" />
<script type="text/javascript" src="<?php echo base_url(); ?>static/js/jquery-excel-export/jquery.btechco.excelexport.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>static/js/jquery-excel-export/jquery.base64.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>static/js/jquery.printElement.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>static/js/bootstrap.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>static/js/jquery.datetimepicker.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>static/js/jquery.validate.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>static/js/form.js"></script>
-->
<script type="text/javascript" src="<?php echo base_url(); ?>static/select2/select2.min.js" ></script>
<script type="text/javascript" src="<?php echo base_url(); ?>static/js/selectSearchGlobal.js"></script>

<script>
    function editBawah(cType,cRequestNo,cSodId) {
        $.post("<?= site_url() ?>search_global/editBawahForm", {
            cType: cType,
            cRequestNo: cRequestNo,
            cSodId: cSodId
        },
        function(data) {
            $('#bawahForm').html(data);
            //$('#container').html(data);
        });
    }
    function deleteBawah(cType,cRequestNo,cSodId) {
        $.post("<?= site_url() ?>search_global/deleteBawahForm", {
            cType: cType,
            cRequestNo: cRequestNo,
            cSodId: cSodId
        },
        function(data) {
            $('#bawahForm').html(data);
            //$('#container').html(data);
        });
    }
    function cancel() {
        $.post("<?= site_url() ?>search_global", function(data) {
            window.location = '<?php echo base_url(); ?>search_global';
        });
    }
    function editSrnKrjOvtSave() {
        //=============================================================
        
        var pAc=''; //
        if (document.getElementById("pAc").checked == true){
            pAc = "Y"; 
        }
        else{
            pAc = "N";
        }
        var pLift=''; //
        if (document.getElementById("pLift").checked == true){
            pLift = "Y"; 
        }
        else{
            pLift = "N";
        }
        var pLighting=''; //
        if (document.getElementById("pLighting").checked == true){
            pLighting = "Y"; 
        }
        else{
            pLighting = "N";
        }
        
        //============================================================
        
        $pJumlahI=$('#jumlahVendor').val();
        //document.write(document.getElementById("pSodId").value); exit;
        var arrId=[""];
        var arrNama=[""];
        var arrLantai=[""];
        var arrLocation=[""];
        var arrVendorId=[""];
        var arrVendorName=[""];
        var x=0;
        for($x=0;$x<$pJumlahI;$x++){
            arrId[$x]=document.getElementById("pSodId"+$x).value;
            arrNama[$x]=document.getElementById('pSodName'+$x).value;
            arrLantai[$x]=document.getElementById('pSodFloor'+$x).value;
            arrLocation[$x]=document.getElementById('pSodLocation'+$x).value;
            arrVendorId[$x]=document.getElementById('r_venid'+$x).value;
            arrVendorName[$x]=document.getElementById('r_vennama'+$x).value; 
        }
        
        //potong kalimat
        var vid=$('#G_Time4').val();
            var pecahan=vid.split(':');
            var nilai1=pecahan[0];
            var nilai2=pecahan[1];
        var cid=$('#G_Time5').val();
            var pecahanC=cid.split(':');
            var nilaiC1=pecahanC[0];
            var nilaiC2=pecahanC[1];    
        var desc=$('#pDescription').val();
            var nilai3=desc.trim();
        
        $.post("<?= site_url() ?>search_global/edit_reqSave", {
            BtnSubmit    		: $('#BtnSubmit').val(),
            pSoId    			: $('#pCtrlID').val(),
            pCType              : $('#pCType').val(),
            pNik    			: $('#pNik').val(),
            pSdate    			: $('#datepicker1').val(),
            pEdate    			: $('#datepicker2').val(),
            pShour    			: nilai1,//$('#pShour').val(),
            pEhour    			: nilaiC1,//$('#pEhour').val(),
            pSminute   		    : nilai2,//$('#pSminute').val(),
            pEminute   		    : nilaiC2,//$('#pEminute').val(),
            pAc    			    : pAc,
            pLift    			: pLift,
            pLighting  		    : pLighting,
            pOtherDescription   : $('#pOtherDescription').val(),
            pDescription  		: nilai3,//$('#pDescription').val(),
            pTotalDetail  		: $('#jumlahVendor').val(),
            pAtasanNik  		: $('#r_mgrid').val(),
            pAtasanNama  		: $('#r_mgr').val(),
            pNikFor    		    : $('#r_id').val(),
            
            
            pReqId    			: $('#pReqId').val(),
            pReqDetId    		: $('#pReqDetId').val(),
            
            //UNTUK PILIHAN TABEL BAWAH
            pSodId              : arrId,
            pSodName            : arrNama,
            pSodFloor           : arrLantai,
            pSodLocation        : arrLocation,
            pSodVendorId        : arrVendorId,
            pSodVendorName      : arrVendorName
            
        },
        function(data) {
            window.location = '<?php echo base_url(); ?>search_global';
        }
        );
    }
</script>

<script>
	$(function() {     //HARUS TERLETAK PALING ATAS DIANTARA LAINNYA
		$("input[id^='datepicker']").datetimepicker({
			scrollInput: false,
			yearOffset:0,
			lang:'en',
			timepicker:false,
			datepicker:true,
			format:'d/m/Y',
			formatDate:'d/m/Y',
			/*minDate:'-1970/01/01',
			onGenerate:function( ct ){
				$(this).find('.xdsoft_date.xdsoft_weekend')
					.addClass('xdsoft_disabled');
			}*/
		});
	});
</script>

<script>
//SCRIPT INI HARUS DIATAS, TIDAK BOLEH DIBAWAH
/* buat coba coba
$(document).ready(function(){
  $("#r_name").change(function(){
    alert("The text has been changed.");
  });
});
*/
$("#r_name").change(function()
{
    //alert(this.id.substr(2));    
	var nik = $(this).val();
	var DataString = {id:nik};
	$.ajax({
			type: "POST",
			url : "<?php echo site_url('search_global/globals_nik_detail')?>",
			dataType: 'json',
			data: DataString,
			success: function(data)
			{
				$("#r_id").val(data.DetailEmp.HR_ID);
                $("#r_nama").val(data.DetailEmp.NAME);
                $("#r_mgrid").val(data.DetailEmp.MANAGER_ID);
				$("#r_mgr").val(data.DetailEmp.MANAGER);
				$("#r_dept").val(data.DetailEmp.ORG);
				$("#r_job").val(data.DetailEmp.JOB_POSITION);
                //$('#r_serial').select2({allowClear: true,placeholder: "Select an attribute"});
                //$('#r_serial').attr('placeholder', 'New Placeholder Text').select2();
                //jQuery(function() 
                //{
                    //$("#r_serial").attr("data-placeholder","bar");
                    //$("#r_serial").select2();
                    //$('#r_serial').attr('placeholder', 'New Placeholder Text').select2();
                //});
                //document.getElementById("r_mgr").value = data.DetailEmp.JOB_POSITION;
                //document.getElementById("r_mgr").value = "";	
				//document.getElementById("r_serial").placeholder = data.DetailEmp.JOB_POSITION;										
			}
			
		});
});


    
    var pJumlahI=$('#jumlahVendor').val();
    var b=0;
    for(b=0;b<pJumlahI;b++){
        //c=b;
        $("#r_venname"+b).change(function() //b=0,b=1,b=2
        {   
            var venid = $(this).val();
        	var DataString = {id:venid};
            var idName=this.id.substr(9); //nilai ini penting bro, buat ngambil nama dari ID 
            	$.ajax({
            			type: "POST",
            			url : "<?php echo site_url('search_global/globals_ven_detail')?>",
            			dataType: 'json',
            			data: DataString,
            			success: function(data)
            			{
       			            //var idName=this.id.substr(9);
                            //alert(idName);
            			    var ab=($('#jumlahVendor').val())-1; 
       			            //Nilai B=pJumlah, entah darimana nilai ini misal 3
            			    var c=b-3;  //c=0 pJumlah-3  if 0 then b-b
                            var d=b-2;  //d=1 pJumlah-2  if 1 then b-(b+1)
                            var e=b-1   //e=2 pJumlah-1  if 2 then b-(b+2)
                            
            				$("#r_venid"+idName).val(data.DetailVen.VENDOR_ID); //b=3,b=3,b=3
                            $("#r_vennama"+idName).val(data.DetailVen.VENDOR_NAME);//b=1,b=2,b=3
            				$("#r_venpic"+idName).val(data.DetailVen.PIC);			
            			}
            			
            		});
        });
    }
    

</script>
<?php
//echo 'tes aja'; exit;
    //QUERY 1
    $this->load->model('sGlobal_model');
    /*$hitungan=$this->sGlobal_model->hitungAja();
    foreach($hitungan as $htg){
        $jumlah=$htg['CNT'];
    }
    echo $jumlah; exit;
    */
    foreach ($getDetail as $z) {
        $zSdate   		   = $z["SO_SDATE"];
		$zEdate   		   = $z["SO_EDATE"];
		$zShours   		   = $z["SO_SHOURS"];
		$zEhours   		   = $z["SO_EHOURS"];
		$zShoure   		   = $z["SO_SHOURE"];
		$zEhoure   		   = $z["SO_EHOURE"];
		$zDescription      = $z["SO_DESCRIPTION"];
		$zAc   			   = $z["SO_AC"];
		$zLift   		   = $z["SO_LIFT"];
		$zLighting   	   = $z["SO_LIGHTING"];
		$zOther   		   = $z["SO_OTHER"];
		$zOtherDescription = $z["SO_OTHER_DESCRIPTION"];
		$zAtasanNik   		= $z["SO_ATASAN_NIK"];
		$zUntukNik   		= $z["SO_UNTUK_NIK"];
		$zAtasanNama   		= $z["ATASANNAME"];

		$cName				= $z["NIKNAME"];
		$cJob				= $z["NIKJOBPOSITION"];
		$cOrg				= $z["NIKORG"];


		if($zAc == 'Y'){
		   $vAc= "checked";
		}

		if($zLift == 'Y'){
		   $vLift= "checked";
		}

		if($zLighting == 'Y'){
		   $vLighting= "checked";
		}

		if($zOther == 'Y'){
		   $vOther= "checked";
		}
        //NANTI DULU
        //if(empty($sesOrg)){
   		//   $org = dbora_getorg("$nik");
    	//}
    }
    
?>



<script type="text/javascript">

    $(document).ready(function() {
        /*
        $('#pNikFor').select2({
            placeholder: "",
            allowClear: true
        });
        $('#pAtasanNama').select2({
            placeholder: "",
            allowClear: true
        });
        */
        var jumlahVendor=$('#jumlahVendor').val();
        //$jmlahVendor=document.getElementById('jumlahVendor').value;
        var a=0;
        for($a=0;$a<jumlahVendor;$a++){
            $("#pSodVendorId"+$a).select2({
                placeholder: "",
                allowClear: true
            });
        }
    });

    


</script>





<!--<div class="container">-->
	<form class="form-horizontal" role="form" method="post" action="#">
    <input type="hidden" value="<?php echo $cRequestNo; ?>" id="pCtrlID" />
    <input type="hidden" value="<?php echo $cType; ?>" id="pCType" />
    <input type="hidden" value="<?php echo $sesNik; ?>" id="pNik" />
    
    
	<div class="col-md-offset-0" id="formuser">
		<div class="col-md-11">
			<div class="panel panel-default">
				<div class="panel-heading"><h4 class="panel-title"><b class="caret"></b><b> Request By</b></h4></div>
				<div class="panel-body">
					<div class="col-xs-12 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-4">Name<span style="color:red;">*</span></label>
							<div class="col-md-7">
                            <input type="text" id="r_name" class="select2 form-control input-sm" placeholder="<?php echo $cName;?>"/>
							<input type="hidden" value="<?php echo $cName;?>" id="r_nama" class="select2 form-control input-sm" readonly="true"/></div>
						</div>					
						<div class="form-group">
							<label class="control-label col-md-4">ID Number</label>
							<div class="col-md-3"><input type="text" value="<?php echo $zUntukNik;?>" id="r_id" class="form-control input-sm" readonly="true"/></div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Manager</label>
							<div class="col-md-7">
                            <!--<input type="text" id="r_serial" class="form-control input-sm"/>-->
                            <input type="text" id="r_mgr" class="form-control input-sm" value="<?php echo $zAtasanNama;?>" readonly=""/>
							<input type="hidden" value="<?php echo $zAtasanNik;?>" id="r_mgrid" class="form-control input-sm" readonly="true"/></div>
						</div>
					</div>
					<div class="col-sm-7 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-4">Departement</label>
							<div class="col-md-7"><input type="text" value="<?php echo $cOrg;?>" id="r_dept" class="form-control input-sm" readonly="true"/></div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Job Position</label>
							<div class="col-md-8"><input type="text" value="<?php echo $cJob;?>" id="r_job" class="form-control input-sm" readonly="true"/></div>
						</div>
					</div>
				</div>
			</div>
			<div class="panel panel-default" style="padding-bottom: 30px;">
				<div class="panel-heading"><h4 class="panel-title"><b class="caret"></b><b> Form</b></h4></div>
				<div class="panel-body">
					<div class="col-xs-12 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-3">Date</label>
							<div class="col-md-6">
								<div class="input-group">
									<span class="input-group-addon"><small>From</small></span>
									<input type="text" class="form-control input-sm" autocomplete="off" name="Other_StartDate" id="datepicker1" value="<?php echo $zSdate?>">
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3"></label>
							<div class="col-md-6">
								<div class="input-group">
									<span class="input-group-addon"><small>To</small></span>
									<input type="text" class="form-control input-sm" autocomplete="off" name="Other_EndDate" id="datepicker2" value="<?php echo $zEdate?>"/>
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3">Time</label>
							<div class="col-md-5">
								<div class="input-group">
									<span class="input-group-addon"><small>From</small></span>										
									<input type="text" class="form-control input-sm" autocomplete="off" name="Other_StartTime" id="G_Time4" value="<?php echo $zShours.":".$zEhours?>"/> 
                                        <!-- id="pShour" id="pSminute" -->
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3"></label>
							<div class="col-md-5">
								<div class="input-group">
									<span class="input-group-addon"><small>To</small></span>										
									<input type="text" class="form-control input-sm" autocomplete="off" name="Other_EndTime" id="G_Time5" value="<?php echo $zShoure.":".$zEhoure?>"/>
                                        <!--id="pEhour" id="pEminute" -->
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3" style="color:red">
								<p><i><small>Overtime</small></i></p>
							</label>
							<div class="col-md-8">
								<label class="control-label col-md-10" style="color:red">
									<p class="text-left"><i><small>Monday ~ Friday 18:00 | Saturday start from 13:00 | Sunday all day.</small></i></p>
								</label>
							</div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<label class="control-label col-md-4">Facility</label>
							<div class="col-md-6">
								<div class="checkbox">
									<label><input id="pAc" type="checkbox" value="Y" <?php if($zAc == 'Y'){?>checked=""<?php }?>/>Air Conditioner</label>
								</div>
								<div class="checkbox">
									<label><input id="pLift" type="checkbox" value="Y" <?php if($zLift == 'Y'){?>checked=""<?php }?>/>Service Lift</label>
								</div>
								<div class="checkbox">
									<label><input id="pLighting" type="checkbox" value="Y" <?php if($zLighting == 'Y'){?>checked=""<?php }?>/>Lighting &amp; Power</label>
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Description</label>
							<div class="col-md-5">
								<textarea id="pDescription" class="form-control input-sm" required="required" style="min-width:190px;max-width:200px;min-height:100px;max-height:200px;"><?php echo $zDescription;?></textarea>
							</div>
						</div>
					</div>
					
					<div class="col-md-12 well well-sm" id="bawahForm">
    					<div id="tablecontent" class="col-md-12" style="padding-top: 0px;">					
    						<div class="form-group">
    							<div class="table-responsive">
    								<table class="table table-bordered table-condensed table-striped" style="background:#f9f9f9;">
    									<thead>
    										<tr>
    											<th class="tblhead" style="width:3%;text-align:center;">No</th>
    											<th class="tblhead" style="width:27%;text-align:center">Name</th>
    											<th class="tblhead" style="width:14%;text-align:center">Floor</th>
    											<th class="tblhead" style="width:10%;text-align:center">Location</th>
    											<th class="tblhead" style="width:10%;text-align:center">Vendor Name</th>	
                                                <th class="tblhead" style="width:10%;text-align:center">Action</th>																				
    										</tr>
    									</thead>
    									<tbody>
                                            <?php
                                                $i=0;
        										$no=1;
                                                foreach ($getDetailVendor as $b) {
                                                            $bSodId   		= $b["SOD_ID"];
        													$bSodName   	= $b["SOD_NAME"];
        													$bSodFloor   	= $b["SOD_FLOOR"];
        													$bSodLocation   = $b["SOD_LOCATION"];
        													$bSodVendorId   = $b["SOD_VENDOR_ID"];
        													$bSodVendorName = $b["SOD_VENDOR_NAME"];
        													$bSoId   		= $b["SO_ID"];
                                            ?>
    										<tr>
    											<td bgcolor="#FFFFFF" class="tbl-content-c" style="width:3%;text-align:center;">
                                                    <?php echo $i+1; ?>
                                                    <input class="form-control input-sm" type="hidden" id="pSodId<?php echo $i;?>" value="<?php echo $bSodId;?>"/>
                                                </td>
    											<td style="width:20%;">
                                                    <input type="text" required="required" id="pSodName<?php echo $i;?>" class="form-control input-sm" value="<?php echo $bSodName;?>"/>
                                                </td>											
    											<td style="width:10%;">
    												<select id="pSodFloor<?php echo $i;?>" class="form-control">
    												<?php
                                                    foreach($getLantai as $c){
                                                        $cFloorDesc   	= $c["MST_FLOOR_DESC"];
    													if($cFloorDesc == $bSodFloor){
    													   ?><option value="<?php echo $cFloorDesc;?>" selected=""><?php echo $cFloorDesc;?></option><?php
    													}
                                                        else{
    													   ?><option value="<?php echo $cFloorDesc;?>"><?php echo $cFloorDesc;?></option><?php
    													}
                                                    }
                                                    ?>
    												</select>
    											</td>											
    											<td style="width:25%;text-align:center">
                                                    <input type="text" required="required" id="pSodLocation<?php echo $i;?>" class="form-control input-sm" value="<?php echo $bSodLocation;?>"/>
                                                </td>
    											<td style="width:35%;text-align:center">
                                                    <input type="hidden"   id="r_venid<?php echo $i;?>" value="<?php echo $bSodVendorId;?>" readonly="" class="form-control input-sm"/>
    						                        <div class="col-md-6">
                                                    <input type="hidden"   id="r_vennama<?php echo $i;?>" value="<?php echo $bSodVendorName;?>" class="form-control input-sm" readonly=""/>
                                                    </div>
                                                    <div class="col-md-12">
                                                    <input type="text" id="r_venname<?php echo $i;?>" placeholder="<?php echo $bSodVendorName;?>" class="select2 form-control input-sm"/>
                                                    </div>
    											</td>
                                                <td>
                                                    <input type="button" class="btn btn-sm btn-primary" value="Edit" onClick="editBawah('<?php echo $cType;?>','<?php echo $cRequestNo; ?>','<?php echo $bSodId; ?>')" />
                                                    <input type="button" class="btn btn-sm btn-danger" value="Delete" onClick="deleteBawah('<?php echo $cType;?>','<?php echo $cRequestNo; ?>','<?php echo $bSodId; ?>')" />
                                                </td>
    										</tr>
    										<?php
                                                $i++;
                                                $no++;
                                            }
                                            ?>
                                            <input type="hidden" id="jumlahVendor" value="<?php echo $i;?>"/>
    									</tbody>
    								</table>
    							</div>
    						</div>
    					</div>
					</div>
					<div class="row"> 
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label class="control-label col-md-3"></label>
        						<div class="col-sm-2">
                                    <button type="button" class="btn btn-primary btn-block" onclick="editSrnKrjOvtSave();">Submit</button>
                                </div>
                                <div class="col-sm-2">
                                    <button type="button" class="btn btn-default btn-block" onclick="cancel();" >Cancel</button>
                                </div>
    				        </div>
                        </div>                   
                    </div>
					
										
				</div>
			</div>
		</div>
	</div>
	</form>
<!--</div>-->


